import React, { useEffect, useState, useRef } from 'react';
import { connect } from 'umi';
import { Form, Button, Card, Input, InputNumber, Popover, notification } from 'antd';
import EditorForm from '@/components/EditorForm';
import FormCondition from '@/components/FormCondition';
import FlxButton from '@/components/FlxButton'
import { InfoCircleOutlined } from '@ant-design/icons'
import { Row, Col, Tooltip, Space, } from 'antd'
const bindAdminSet = (props) => {
    const { dispatch, reload, id, initialValues } = props;
    const [params, setParams] = useState({
        assignAdminFlag: '0'
    })
    const [list, setList] = useState([])
    const [data, setData] = useState({})
    const [form] = Form.useForm();
    const [organizationAuthAdminList, setOrganizationAuthAdminList] = useState([])
    const { assignAdminFlag } = params
    // 新增修改 传id修改 不传id新增=
    const fetchRoleEdit = () => {
        form.validateFields().then((values) => {
            const { assignAdminIds, assignAdminFlag } = values
            dispatch({
                type: 'promoter/fakeSetAssignAdmin',
                payload: {
                    id,
                    ...values,
                    assignAdminIds: assignAdminFlag === '1' ? assignAdminIds.toString() : ''
                },
            })
        });
    };
    useEffect(() => {
        dispatch({
            type: 'weCom/fetchSearchOrganizationAdminAll',
            payload: {
                page: 1,
                limit: 9999,
                status: '1'
            },
            callback: (e) => {
                setOrganizationAuthAdminList(e)
            }
        });
    }, [])

    useEffect(() => {
        const { assignAdminFlag } = initialValues
        setParams({ assignAdminFlag })
    }, [initialValues])
    const { assignAdminIds = '' } = initialValues
    const formItemLayout = {
        labelCol: {
            sm: { span: 0 },
        },
        wrapperCol: {
            sm: { span: 0 },
        },
    };
    const formItems = [
        {
            label: '是否绑定员工',
            name: 'assignAdminFlag',
            onChange: (e) => {
                form.setFieldsValue({
                    assignAdminIds: []
                })
                setList([])
                setParams({
                    assignAdminFlag: e.target.value
                })
            },
            type: 'radio',
            select: {
                0: '否',
                1: '是',
            },
        },
        {
            label: '员工选择',
            visible: assignAdminFlag == '1',
            name: 'assignAdminIds',
            type: 'select',
            mode: 'multiple',
            select: organizationAuthAdminList,
            fieldNames: { label: 'username', value: 'id' },
        },
        // {
        //     visible: assignAdminFlag == '1',
        //     type: 'noForm',
        //     formItem: <SetAdminList initialValues={initialValues} list={list} setList={setList}></SetAdminList>
        // },
    ];


    return (
        <div style={{ fontSize: 28 }}>
            <Row>
                <Col span={18}>
                    <div style={{ paddingTop: 12 }}>
                        <FormCondition formItemLayouts={formItemLayout} form={form} formItems={formItems} initialValues={{
                            ...initialValues, assignAdminIds: assignAdminIds.length > 0 ? assignAdminIds.split(',').map(val => {
                                return parseInt(val)
                            }) : []
                        }}></FormCondition>
                    </div>
                </Col>
                <FlxButton onOk={fetchRoleEdit}></FlxButton>
            </Row>
        </div>
    );
};

export default connect(({ institution, loading }) => ({
    loading: loading.models.institution,
}))(bindAdminSet);
